<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<link href="${basePath}/js/fileInput/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
<!doctype html>
<html>
<head>
<style type="text/css">
	.ibox-content{
		border: none;
	}
	
	.progress {
   	 	margin-top: 15px!important;
   	 	margin-bottom:0px;
	}
	
	.ibox-zxsearchqu {
	    padding-bottom: 5px!important;
	}
</style>
</head>
<body class="gray-bg">
<div class="container creditbody">
	 <div class="iboxtitle">
	 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷后业务>逾期风控>导入逾期客户</span>
     </div>
     <div class="ibox-content ibox-zxsearchqu">
          <div class="uploadfile-btn">
	         <form  enctype="multipart/form-data">
				<input type="hidden" id="uploadName"/>
	          	<input id="uploadfile" name="uploadfile" type="file" multiple data-min-file-count="1"/>
	         </form>
       	  </div>
       	  
		  <div  class="uploadfile-btnb td-width">
              	<select class="select-control" id="bankCode" name="bankCode"  >
				  </select>
           </div>		
          <div  class="uploadfile-btnc">
          	<button class="btn dpbtn_grey_heigth" type="button" onclick="preview();">导入预览</button>
          	<button class="btn dpbtn_grey_heigth" type="button" onclick="importDueList();">确认导入</button>
          	<button class="btn dpbtn_grey_heigth" type="button" onclick="windowopen()">逾期数据调整</button>
          </div>
      </div>


         <div class="ibox-content">	
          	<div class="jqGrid_wrapper">
	             <table id="table_list_1"></table>
	             <div id="pager_list_1"></div>
         	</div>
         </div>
</div>
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>	
    <script src="${basePath}/js/fileInput/js/fileinput.js" type="text/javascript"></script>
    <script src="${basePath}/js/fileInput/js/locales/zh.js" type="text/javascript"></script>
    
    <!-- custom js -->
    
    
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		var lastSel;
	    jQuery(function($) { 
   		initTable();
   		initBankDic();
    	 var fileBtn = $("input[type=file]");
    	    fileBtn.on("change", function(){
    	        var index = $(this).val().lastIndexOf("\\");
    	        var sFileName = $(this).val().substr((index+1));
    	        $("#rightText").html(sFileName);
    	    });
	    });
	    var initBankDic=function(){
	    	$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
		    	
	 			data:{
	 				"parentValue":"LoanBank"
	 			},
	 			success: function(datas){
	 				  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var programme_sel=[];
		 				      for(var i=0;i<result.length;i++){
		 				          var programme = result[i];
		 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
		 				      }
		 				     $("#bankCode").html(programme_sel.join(' '));
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	              }
		    	});
	    }
	    var windowopen=function(){
	    	 window.open("${basePath}/web/system/loanAfter/dhOverduechangeList.jsp","_self");	
	    }
	    
	   var importDueList=function(){
		   var uploadfile = $("#uploadName").val();
	 	    if(uploadfile==""){
	 	    	layer.msg('请先上传表格，再导入！', {icon: 5});
	 	    	return false;
	 	    }
		   var bankCode=$('#bankCode option:selected').val();
		   $.dpAjax({
	    		url:'${basePath}/DhOverdueController/batchImportDueList',
	    		data:{"uploadName":$("#uploadName").val(),"bankCode":bankCode},
   				success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  var weipipei = datas.result.weipipei;
	    				  var yipipei = datas.result.yipipei;
						  layer.msg('数据正在导入中。。。', {icon: 16});
						  layer.confirm('导入成功，其中已匹配数据'+yipipei+'条，未匹配数据'+weipipei+'条 !', {
		   		  			  btn: ['确定','取消'] //按钮
		   				   },function(){
		   					layer.closeAll();
		   				   }); 
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
                }
	    	});
	   }
	   var initTable=function(){
		   var winWidth = $('div.ibox-content').width();
	        var winHeight = document.body.offsetHeight - 300;
	     	var win = winWidth / 7 - 20;
	 	    $.jgrid.defaults.styleUI = 'Bootstrap';
	 	    var initFlag=true;
			$("#table_list_1").jqGrid({
				url:'${basePath}/DhOverdueController/previewDueList',
		       	datatype : "json",
		       	postData:{"uploadName":$("#uploadName").val(),"initFlag":initFlag},
			    colNames : ['客户姓名','身份证号','贷款额', '逾期金额','累计逾期次数','每期款项','逾期日期'],
			    colModel : [ 
		             {name: 'cusName',index: 'cusName',width: 130,align: "center",sorttype: "float"},
		             {name: 'cusIdno',index: 'cusIdno',width: 170,align: "center",sorttype: "float"},
		             {name: 'loanAmount',index: 'loanAmount',width: 130,align: "center",sorttype: "float"},
		             {name: 'overdueCountContinuous',index: 'overdueCountContinuous',width: 130,align: "center",sorttype: "float"},
		             {name: 'overdueCountTotal',index: 'overdueCountTotal',width: 130,align: "center",sorttype: "float"},
		             {name: 'amountMonthly',index: 'amountMonthly',width: 130,align: "center",sorttype: "float"},
		             {name: 'dateOverdue',index: 'dateOverdue',width: 170,align: "center",sorttype: "float"}
		             ],
		           mtype : "post",
		           height: winHeight,
		           width:winWidth,  
		           autowidth: false,
		           shrinkToFit: false,
		           rowNum: 15,
		           rowList: [15, 30, 45],
		           viewrecords: true,
		           pager: "#pager_list_1",
		           hidegrid: false,
		           multiselect : false,		//实现单选    multiboxonly:true   beforeSelectRow: true,
		           multiboxonly:false,  
		           beforeSelectRow: false,
		           altRows:true,
		           altclass:'someClass',
		           loadComplete: function(datas){
		        	   if(datas.flag==100100){
		        		   if(initFlag==false){
			        		   layer.msg('预览成功！', {icon: 6});
		        		   }
			        	   return;
		        	   }
		        	   if(datas.flag == '100802') {
		 				  top.location.href = thisLoginUrl;
		 				  return;
			 			}
		        	   if(datas.flag==100300){
		        		   layer.msg('请选择正确的表格，再导入！', {icon: 5});
		        		   return;
		        	   }
		        	   $.fn.showDatas({"datas":datas});
		        	   return ;
		           },
		           jsonReader: {
		                root: "result.rows",
		                page: "result.page",
		                total: "result.total",
		                records: "result.records",
		                repeatitems: false,
		                id: "replaceId"
		            }
		      });
	   }
	    
	var preview = function(){
		var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
    	var data = {};
    	var uploadfile = $("#uploadName").val();
  	    if(uploadfile==""){
  	    	layer.msg('请先上传表格，再预览！', {icon: 5});
  	    	return false;
  	    }
    	data.uploadName =$("#uploadName").val() || '';
    	data.initFlag=false;
    	$.extend(postData, data);
		$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}])
	}
    window.onresize = function()
    {
    	 $("#table_list_1").setGridWidth($(window).width()-80);
    	 $("#table_list_1").setGridHeight($(window).height() / 2.5);
    }
    var carSeriesChoose=function(){
    	
    }
	var carSeriesUnChoose=function(){
    	
    }
	$("#uploadfile").fileinput({
		language: 'zh', //设置语言
	   	 uploadUrl: "${basePath}/FileController/upload", //上传的地址(访问接口地址)
	   	 allowedFileExtensions: ['xlsx'],//接收的文件后缀
	   	 showUpload: false, //是否显示上传按钮
	   	 showRemove : false, //显示移除按钮
	   	 showPreview : false, //是否显示预览
	   	 dropZoneEnabled: false,//是否显示拖拽区域
	   	 minImageWidth:'1',
	   	uploadExtraData:{"flag":true},
	    }).on("filebatchselected", function(event, files) {
	            $(this).fileinput("upload");
	           
	        })
	        .on("fileuploaded", function(event, datas) {
	        	jQuery("#table_list_1").jqGrid("clearGridData");
	        	 if(datas.response.flag==100100){
			  			$("#uploadName").val(datas.response.result.name);
			  }
	    });
    </script>
</body>
</html>
